package com.udf.AopShow.Aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by zwr on 2014/11/13.
 */
@Aspect
@Component
public class MethodInvocationAspect {

    @Pointcut("execution(* com.udf.AopShow.service..*.listName())")
    public void listNamePoint(){};

    @Around("listNamePoint()")
    public String listNameAspect(ProceedingJoinPoint pjp) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        MethodSignature m = (MethodSignature) pjp.getSignature();
        System.out.println("declaringType:"+m.getDeclaringType());
        Method permissonMethod = m.getDeclaringType().getMethod(m.getMethod().getName(),String.class);
        return (String) permissonMethod.invoke(pjp.getTarget(), "aba");
    }

}
